package cn.edu.scau.dropship.mapper;

import cn.edu.scau.dropship.entity.Goods;
import cn.edu.scau.dropship.entity.GoodsExample;
import java.util.List;
import org.apache.ibatis.annotations.Arg;
import org.apache.ibatis.annotations.ConstructorArgs;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface GoodsMapper {
    @SelectProvider(type=GoodsSqlProvider.class, method="countByExample")
    long countByExample(GoodsExample example);

    @DeleteProvider(type=GoodsSqlProvider.class, method="deleteByExample")
    int deleteByExample(GoodsExample example);

    @Delete({
        "delete from goods",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into goods (id, title, ",
        "length, width, height, ",
        "weight, sku, upc, ",
        "ena, model, price, ",
        "warranty_time, ebay_description, ",
        "amazon_description, image, ",
        "state, classification_id, ",
        "brand_id)",
        "values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, ",
        "#{length,jdbcType=DOUBLE}, #{width,jdbcType=DOUBLE}, #{height,jdbcType=DOUBLE}, ",
        "#{weight,jdbcType=DOUBLE}, #{sku,jdbcType=VARCHAR}, #{upc,jdbcType=VARCHAR}, ",
        "#{ena,jdbcType=VARCHAR}, #{model,jdbcType=VARCHAR}, #{price,jdbcType=DOUBLE}, ",
        "#{warrantyTime,jdbcType=VARCHAR}, #{ebayDescription,jdbcType=VARCHAR}, ",
        "#{amazonDescription,jdbcType=VARCHAR}, #{image,jdbcType=VARCHAR}, ",
        "#{state,jdbcType=VARCHAR}, #{classificationId,jdbcType=INTEGER}, ",
        "#{brandId,jdbcType=INTEGER})"
    })
    int insert(Goods record);

    @InsertProvider(type=GoodsSqlProvider.class, method="insertSelective")
    int insertSelective(Goods record);

    @SelectProvider(type=GoodsSqlProvider.class, method="selectByExample")
    @ConstructorArgs({
        @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
        @Arg(column="title", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="length", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="width", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="height", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="weight", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="sku", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="upc", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="ena", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="model", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="price", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="warranty_time", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="ebay_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="amazon_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="image", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="classification_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
        @Arg(column="brand_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Goods> selectByExample(GoodsExample example);

    @Select({
        "select",
        "id, title, length, width, height, weight, sku, upc, ena, model, price, warranty_time, ",
        "ebay_description, amazon_description, image, state, classification_id, brand_id",
        "from goods",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ConstructorArgs({
        @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
        @Arg(column="title", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="length", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="width", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="height", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="weight", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="sku", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="upc", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="ena", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="model", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="price", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="warranty_time", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="ebay_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="amazon_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="image", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="classification_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
        @Arg(column="brand_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    Goods selectByPrimaryKey(Integer id);

    @UpdateProvider(type=GoodsSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Goods record, @Param("example") GoodsExample example);

    @UpdateProvider(type=GoodsSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Goods record, @Param("example") GoodsExample example);

    @UpdateProvider(type=GoodsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Goods record);

    @Update({
        "update goods",
        "set title = #{title,jdbcType=VARCHAR},",
          "length = #{length,jdbcType=DOUBLE},",
          "width = #{width,jdbcType=DOUBLE},",
          "height = #{height,jdbcType=DOUBLE},",
          "weight = #{weight,jdbcType=DOUBLE},",
          "sku = #{sku,jdbcType=VARCHAR},",
          "upc = #{upc,jdbcType=VARCHAR},",
          "ena = #{ena,jdbcType=VARCHAR},",
          "model = #{model,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=DOUBLE},",
          "warranty_time = #{warrantyTime,jdbcType=VARCHAR},",
          "ebay_description = #{ebayDescription,jdbcType=VARCHAR},",
          "amazon_description = #{amazonDescription,jdbcType=VARCHAR},",
          "image = #{image,jdbcType=VARCHAR},",
          "state = #{state,jdbcType=VARCHAR},",
          "classification_id = #{classificationId,jdbcType=INTEGER},",
          "brand_id = #{brandId,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Goods record);

    @Select("select * from goods where brand_id = #{brandId}")
    @ConstructorArgs({
            @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
            @Arg(column="title", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="length", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="width", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="height", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="weight", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="sku", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="upc", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="ena", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="model", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="price", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="warranty_time", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="ebay_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="amazon_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="image", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="classification_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="brand_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Goods> getAllGoods(Integer brandId);


    @Select("select goods.id , goods.title , goods.length , goods.width , goods.height , goods.weight , goods.sku , goods.upc , goods.ena , goods.model , goods.price , goods.warranty_time , goods.ebay_description , goods.amazon_description , goods.image , goods.state , goods.classification_id , goods.brand_id from goods , brand where goods.brand_id = brand.id and  brand.mvo_id = #{mvo_id}")
    @ConstructorArgs({
            @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
            @Arg(column="title", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="length", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="width", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="height", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="weight", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="sku", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="upc", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="ena", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="model", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="price", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="warranty_time", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="ebay_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="amazon_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="image", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="classification_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="brand_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Goods> selectGoodsByCompanyID(Integer mvo_id);

    @Select("select * from goods where title = #{title} ")
    @ConstructorArgs({
            @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
            @Arg(column="title", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="length", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="width", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="height", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="weight", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="sku", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="upc", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="ena", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="model", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="price", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="warranty_time", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="ebay_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="amazon_description", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="image", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="classification_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="brand_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    Goods selectGoodsByTitle(@Param("title") String title);

    @Update({
            "update goods",
            "set state = 'W'",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int uploadToStorehouse(Integer id );

    @Update({
            "update goods",
            "set state = 'A'",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int uploadToStore(Integer id);

    @Update({
            "update goods",
            "set state = 'S'",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int offstorehouse(Integer id);


    @Update({
            "update goods",
            "set state = 'W'",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int goOffFromStore(Integer id);
}